package com.jxinternet.platform.services.repository.convert;

import com.jxinternet.platform.services.entity.cassandra.FishCassandra;
import com.jxinternet.platform.services.entity.domian.Fish;
import com.jxinternet.platform.services.entity.mysql.FishMysql;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/8/22.
 */
@Service
public class FishContert implements BaseConvert<Fish,FishMysql,FishCassandra>{


    @Override
    public FishMysql convertMysql(Fish fish) {
        if (fish == null) {
            return null;
        }

        return copyEntityToMysql(fish);
    }

    @Override
    public FishCassandra convertCassandra(Fish fish) {
        if (fish == null) {
            return null;
        }
        return  copyEntityToCassandra(fish);
    }

    @Override
    public  Fish convertMysqlDomainToModel(FishMysql fishMysql) {
        if (fishMysql == null) {
            return null;
        }
        return copyMysqlToEntity(fishMysql);
    }

    @Override
    public Fish convertCassandraDomainToModel(FishCassandra fishCassandra) {
        if (fishCassandra == null) {
            return null;
        }
        return copyCassandraToEntity(fishCassandra);
    }


    private static Fish copyMysqlToEntity(FishMysql fishMysql){
        Fish fish=new Fish();
        fish.setId(fishMysql.getId());
        fish.setFishCode(fishMysql.getFishCode());
        fish.setFishName(fishMysql.getFishName());
        fish.setOdds(fishMysql.getOdds());
        fish.setChance(fishMysql.getChance());
        fish.setState(fishMysql.getState());
        fish.setPlatformNo(fishMysql.getPlatformNo());
        fish.setCreateTime(fishMysql.getCreateTime());
        fish.setUpdateTime(fishMysql.getUpdateTime());
        fish.setVersion(fishMysql.getVersion());
        return  fish;

    }

    private static Fish copyCassandraToEntity(FishCassandra fishCassandra){
        Fish fish=new Fish();
        fish.setId(fishCassandra.getId());
        fish.setFishCode(fishCassandra.getFishCode());
        fish.setFishName(fishCassandra.getFishName());
        fish.setOdds(fishCassandra.getOdds());
        fish.setChance(fishCassandra.getChance());
        fish.setState(fishCassandra.getState());
        fish.setPlatformNo(fishCassandra.getPlatformNo());
        //fish.setCreateTime(fishCassandra.getCreateTime());
        //fish.setUpdateTime(fishCassandra.getUpdateTime());
        //fish.setVersion(fishCassandra.getVersion());
        return  fish;
    }

    private static FishMysql copyEntityToMysql(Fish fish){
        FishMysql fishMysql=new FishMysql();
        fishMysql.setId(fish.getId());
        fishMysql.setFishCode(fish.getFishCode());
        fishMysql.setFishName(fish.getFishName());
        fishMysql.setOdds(fish.getOdds());
        fishMysql.setChance(fish.getChance());
        fishMysql.setState(fish.getState());
        fishMysql.setPlatformNo(fish.getPlatformNo());
        fishMysql.setCreateTime(fish.getCreateTime());
        fishMysql.setUpdateTime(fish.getUpdateTime());
        fishMysql.setVersion(fish.getVersion());
        return  fishMysql;
    }

    private static FishCassandra copyEntityToCassandra(Fish fish){
        FishCassandra fishCassandra=new FishCassandra();
        fishCassandra.setId(fish.getId());
        fishCassandra.setFishCode(fish.getFishCode());
        fishCassandra.setFishName(fish.getFishName());
        fishCassandra.setOdds(fish.getOdds());
        fishCassandra.setChance(fish.getChance());
        fishCassandra.setState(fish.getState());
        fishCassandra.setPlatformNo(fish.getPlatformNo());
        //fishCassandra.setCreateTime(fish.getCreateTime());
        //fishCassandra.setUpdateTime(fish.getUpdateTime());
        //fishCassandra.setVersion(fish.getVersion());
        return  fishCassandra;
    }
}
